import 'package:app/common/colors.dart';
import 'package:app/common/tool.dart';
import 'package:app/components/base_scaffold_appbar.dart';
import 'package:app/services/address.dart';
import 'package:app/services/dio_manager.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
class CalendarAlamView extends StatefulWidget {
  const CalendarAlamView({Key? key}) : super(key: key);

  @override
  State<CalendarAlamView> createState() => _CalendarAlamViewState();
}

class _CalendarAlamViewState extends State<CalendarAlamView> {


  CalendarAlarmModel? model;

  /// 请求数据
  requestData()async{

    var json  = await DioManager().kkRequest(Address.calendarAlarm,method: 'get');

    CalendarAlarmModel _model = CalendarAlarmModel.fromJson(json);

    model = _model;

    setState(() {

    });

  }
  @override
  void initState() {
    super.initState();
    requestData();
  }




  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: BaseAppBar(
        preferredSize: Size(Get.width, AppTool.appBarHEIGHT),
        child: Text('提醒类型'),
      ),
      body: ListView.builder(itemBuilder: (BuildContext context, int index) {

        return GestureDetector(
          onTap: (){
            var params = {
              'id':model!.data?[index].id,
              'name':model!.data?[index].name,
            };
            Get.back(result: params);
          },
          child: Container(
            color: Colors.white,
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Container(
                  padding: EdgeInsets.all(15),
                  child: Text('${model?.data?[index].name}'),
                ),
                Container(
                  height: 0.5,
                  color: AppColor.lineColor,

                )
              ],
            ),
          ),
        );

      },itemCount: model?.data?.length??0,),
    );

  }
}


class CalendarAlarmModel {
  int? errcode;
  String? errmsg;
  List<Data>? data;
  String? message;

  CalendarAlarmModel({this.errcode, this.errmsg, this.data, this.message});

  CalendarAlarmModel.fromJson(Map<String, dynamic> json) {
    errcode = json['errcode'];
    errmsg = json['errmsg'];
    if (json['data'] != null) {
      data = <Data>[];
      json['data'].forEach((v) {
        data!.add(new Data.fromJson(v));
      });
    }
    message = json['message'];
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['errcode'] = this.errcode;
    data['errmsg'] = this.errmsg;
    if (this.data != null) {
      data['data'] = this.data!.map((v) => v.toJson()).toList();
    }
    data['message'] = this.message;
    return data;
  }
}

class Data {
  int? id;
  String? name;

  Data({this.id, this.name});

  Data.fromJson(Map<String, dynamic> json) {
    id = json['id'];
    name = json['name'];
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['id'] = this.id;
    data['name'] = this.name;
    return data;
  }
}
